home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig11_24.jar / Ch11 / Fig11_24 / Fig11_24.cpp
C/C++ Source or Header  |  1997-10-29  |  1KB  |  34 lines

  1. // Fig. 11.24: fig11_24.cpp 
  2. // Using the fill member function and the setfill
  3. // manipulator to change the padding character for
  4. // fields larger than the values being printed.
  5. #include <iostream.h>
  6. #include <iomanip.h>
  7.  
  8. int main()
  9. {
  10.    int x = 10000;
  11.  
  12.    cout << x << " printed as int right and left justified\n"
  13.         << "and as hex with internal justification.\n"
  14.         << "Using the default pad character (space):\n";
  15.    cout.setf( ios::showbase );
  16.    cout << setw( 10 ) << x << '\n';
  17.    cout.setf( ios::left, ios::adjustfield );
  18.    cout << setw( 10 ) << x << '\n';
  19.    cout.setf( ios::internal, ios::adjustfield );
  20.    cout << setw( 10 ) << hex << x;
  21.  
  22.    cout << "\n\nUsing various padding characters:\n";
  23.    cout.setf( ios::right, ios::adjustfield );
  24.    cout.fill( '*' );
  25.    cout << setw( 10 ) << dec << x << '\n';
  26.    cout.setf( ios::left, ios::adjustfield );
  27.    cout << setw( 10 ) << setfill( '%' ) << x << '\n';
  28.    cout.setf( ios::internal, ios::adjustfield );
  29.    cout << setw( 10 ) << setfill( '^' ) << hex << x << endl;
  30.    return 0;
  31. }
  32.  
  33.  
  34.